//
//  TIMApi.h
//  TIMLib
//
//  Created by Deli Xia on 2018/5/15.
//  Copyright © 2018年 Deli Xia. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TIMCommon.h"
#import "TIMMessage.h"


@class TIMSdkConfig;
@interface TIMApi : NSObject

/**
 *  This method provides initialization for login APIs.
 */
+ (void)initSdk:(TIMSdkConfig *)config;

/**
 *  This method is used to release login APIs.
 */
+ (void)destroy;

/**
 *  This method enterBackground.
 */
+ (void)enterBackground;

/**
 *   This method enterForground.
 */
+ (void)enterForground;

/**
 登陆
 @param userId       用户名
 @param password     密码
 */
+ (void)login:(NSString *)userId password:(NSString *)password completion:(nullable void (^)(NSError *error))completion;


/**
 注销
 */
+ (void)logout:(nullable void (^)(NSError *error))completion;

/**
 从服务器获取好友列表
 @param userId      用户ID
 */
+ (void)queryContactsFromServerWithUserId:(NSString *)userId completion:(nullable void (^)(NSError *error))completion;

/**
 发送消息
 @param message         消息模型
 @param content         发送的内容， 文本是text,图片是url,表情是url。
 @param isGroup         代表群组还是朋友，传入1代表是群组，0代表是朋友
 @param msgSnapshot     是否是阅后即焚消息
 @param aateArray       @的人
 */
+ (void)sentMessage:(TIMMessage *)message content:(NSString *)content isGroup:(NSInteger)isGroup msgSnapshot:(BOOL)msgSnapshot aateArray:(NSArray *)aateArray completion:(nullable void (^)(NSError *error))completion;

/**
 撤回消息
 @param message         消息模型
 @param isGroup         代表群组还是朋友，传入1代表是群组，0代表是朋友
 */
+ (void)revokeMessage:(TIMMessage *)message isGroup:(NSInteger)isGroup completion:(nullable void (^)(NSError *error))completion;

/**
 删除消息 isGroup 1代表是群组，0代表是朋友
 @param message         消息模型
 @param isGroup         代表群组还是朋友，传入1代表是群组，0代表是朋友
 */
+ (void)deleteMessage:(TIMMessage *)message isGroup:(NSInteger)isGroup completion:(nullable void (^)(NSError *error))completion;

/**
 上传文件
 @param filename        文件名
 @param filemd5         md5加密后的值
 @param filesize        文件大小
 @param message         需要发送的消息
 */
+ (void)uploadUrlRequestFilename:(NSString *)filename filemd5:(NSString *)filemd5 filesize:(int)filesize message:(TIMMessage *)message completion:(nullable void (^)(NSError *error))completion;

/**
 上传头像
 @param filename        图片名
 @param filemd5         md5加密后的值
 @param filesize        图片大小
 */
+ (void)uploadHeadUrlRequestWithFilename:(NSString *)filename filemd5:(NSString *)filemd5 filesize:(long long)filesize completion:(nullable void (^)(NSError *error))completion;

/**
 修改用户信息
 */
+ (void)modifyUserInfoWithNickName:(nullable NSString *)nickname headurl:(nullable NSString *)headurl persionalnote:(nullable NSString *)persionalnote completion:(nullable void (^)(NSError *error))completion;

/**
 发送添加好友请求
 @param senderId     添加人的ID
 @param receiverId   接受人的ID
 @param msgMemo      备注
 @param msgGroup     分组
 @param msgTip       添加好友时的提示内容
 @parma msgOp        处理好友关系
 */
+ (void)addFriendWithSenderId:(NSString *)senderId
                   ReceiverId:(NSString *)receiverId
                      MsgMemo:(NSString *)msgMemo
                     MsgGroup:(NSData *)msgGroup
                       MsgTip:(NSData *)msgTip
                 MsgOperation:(TIMMessageFriendOperation)msgOp
                   completion:(nullable void (^)(NSError *error))completion;

/**
 *获取好友资料
 @param userID        朋友ID
 */
+ (void)queryFriendInfoWithUserId:(NSString *)userID completion:(nullable void (^)(NSError *error))completion;

/**
 *获取群组名片
 */
+ (void)queryGroupVcardRequest:(NSString *)groupID completion:(nullable void (^)(NSError *error))completion;

/**
 获取群成员 @version:  0代表全拉
 */
+ (void)queryGroupUserFromServerWithGroupId:(NSString *)GrpID version:(NSInteger)version completion:(nullable void (^)(NSError *error))completion;

/**
 获取群成员资料
 @param membersId     需要被拉取的群成员ID,
 @param groupId     群组ID
 */
+ (void)queryGroupMemberInfoRequest:(NSArray *)membersId groupId:(NSString *)groupId completion:(nullable void (^)(NSError *error))completion;

/**
 *群公告
 * 老接口
 */
+ (void)queryGroupAnnounceMentRequestWithGroupId:(NSString *)groupID grpUid:(NSString *)grpUid grpAnnOp:(TIMAnnounceMent_Operation)grpAnnOp groupAnnounceContent:(NSString *)grpAnnounceContent completion:(nullable void (^)(NSError *error))completion;

/**
 操作群组请求
 @param groupId      被操作群组的ID，创建群组因为没有ID，可以设为0
 @param userId       只有在扫码入群时才填展示人ID，其他可填空
 @param msg_op       操作类型（备注：TIMOperateGroupType枚举）
 @param members      被操作人<TIMUserInfo>
 @param groupName    群组名字，创建的时候填写，其他操作可设为空
 */   
+ (void)operateGroupWithGroupId:(NSString *)groupId
                  operateUserId:(NSString *)userId
                   MsgOperation:(TIMOperateGroupType)msg_op
                   groupMembers:(NSArray<TIMUserInfo *> *)members
                      GroupName:(NSData *)groupName
                     completion:(nullable void (^)(NSError *error))completion;

/**
 修改好友昵称
 @param friendId        好友ID
 @param memo            昵称
 */
+ (void)modifyFriendId:(NSString *)friendId memo:(NSString *)memo completion:(nullable void (^)(NSError *error))completion;

/**
 *历史消息
 @param limit          查询历史消息数据限制
 @param msgSender      发送方的ID
 @param msgKey         最后一条消息的msgkey
 @param msgGlobalId    最后一条消息的globalID
 @param completion     调用结束后的回调
 */
+ (void)queryHistoryMessageWithlimit:(int)limit msgSender:(NSString *)msgSender msgKey:(NSInteger)msgKey msgGlobalId:(NSInteger)msgGlobalId completion:(nullable void (^)(NSError *error))completion;

/**
 *好友和群组免打扰设置接口
 disturb  是否免打扰
 SessionId 好友或者群组ID
 isGroup  1代表是群组，0代表是好友
 */
+ (void)personalSetWithSessionId:(NSString *)SessionId disturb:(BOOL)disturb isGroup:(NSInteger)isGroup completion:(nullable void (^)(NSError *error))completion;
/**
 *置顶消息
 @param sessionId    置顶消息ID
 @param isTop        是否要置顶
 */
+ (void)setTopMessageBySessionId:(NSString *)sessionId isTop:(BOOL)isTop;

/**
 *阅后即焚功能
 @param sessionId    朋友或群组ID
 @param isBurn        是否开启阅后即焚功能
 */
+ (void)setupBurnAfterReadBySessionid:(NSString *)sessionId isBurn:(BOOL)isBurn;

/**
 *点击阅后即焚消息
 @param message    消息key
 @param messageType        消息类型
 */
+ (void)touchUpMessage:(TIMMessage *)message messageType:(TIMMessageType)messageType clickState:(TIMMessageClickState)clickState;

// 检测到没网
+ (void)checkWhetherIsNetwork:(BOOL)isNetwork;

/**
 操作群组请求
 @param groupId      被操作群组的ID，创建群组因为没有ID，可以设为0
 @param msg_op       邀请四种操作类型（备注：TIMOperateGroupType枚举）
 @param members      被操作人
 */
+ (void)inviteOperationWithGroup:(NSString *)groupId
                   inviteRemarks:(NSString *)remarks
                  inviteAuditAck:(NSString *)auditAck
                    MsgOperation:(TIMOperateGroupType)msg_op
                    groupMembers:(NSArray *)members
                      completion:(nullable void (^)(NSError *error))completion;

#pragma mark - 评论组相关（直播
/**
 操作评论组
 @param groupId       被操作群组的ID，创建群组因为没有ID，设为0
 @param userId        操作人的ID
 @param msg_op        操作类型（备注：创建群组设置为MsgOperation_OperationGrpCreate，以此类推）
 @param members       被操作人的ID
 @param groupName     群组名字，创建的时候填写，其他操作可设为空
 @param msgResourceId 评论组的资源id
 */
+ (void)operateReviewGroupWithGroupId:(NSString *)groupId
                        operateUserId:(NSString *)userId
                         MsgOperation:(TIMOperationCommentGroup)msg_op
                         groupMembers:(NSArray<TIMUserInfo *> *)members
                            GroupName:(NSString *)groupName
                        MsgResourceId:(NSString *)msgResourceId
                           completion:(nullable void (^)(NSError *error))completion;

/**
 *发送评论组消息
 */
+ (void)sentReviewGroupMessageWithSenderId:(NSString *)senderId  ReceiverId:(NSString *)receiverId MsgContent:(NSString *)msgContent msgType:(NSInteger)msgType completion:(nullable void (^)(NSError *error))completion;

/**
 *根据资源ID查询评论组的ID
 */
+ (void)queryCommentGroupByResourceID:(NSString *)resourceID completion:(nullable void (^)(NSError *error))completion;

/**
 *获取评论组禁言列表
 * NSMutableArray<userId>
 */
+ (void)queryCommentStopTalkListWithResourceId:(nonnull NSString *)resourceId groupId:(nonnull NSString *)groupId success:(nullable void(^)(id response))successCompletion failer:(nullable void (^)(NSError *error))completion;

#pragma mark - Group File

/**
 获取文件列表
 @param groupId        groupId
 @param totalcnt       暂时忽略，传0
 @param gotcount       暂时忽略，传0
 @param version        第一次传0，后续传当前user的version
 @param successCompletion       id<NSArray><TIMGroupFileInfo>;
 */
+ (void)queryGroupFileListWithGroupId:(NSString *)groupId totalcount:(NSInteger)totalcnt gotcount:(NSInteger)gotcount version:(NSString *)version success:(nullable void(^)(id response))successCompletion completion:(nullable void (^)(NSError *error))completion;

/**
 文件上传申请
 @param groupId           groupId
 @param filemd5           nil
 @param fileSize          nil
 @param permoption       权限控制，后台不做处理
 @param successCompletion    id<NSDictionary>  = @{@"fileid":TIMNoNilString(fileid), @"fileurl":TIMNoNilString(fileurl), @"filetoken":TIMNoNilString(filetoken), @"filekey":TIMNoNilString(filekey),@"secondPass":secondPass};  "secondPass":[NSNumber bool] 代表是否是秒传，若是秒传，则客户端不需要上传七牛。直接返回成功
 */
+ (void)applyForUploadRequestWithGroupId:(NSString *)groupId filemd5:(NSString *)filemd5 fileSize:(NSString *)fileSize permoption:(NSString *)permoption filename:(NSString *)fileName fileType:(NSString *)fileType success:(nullable void(^)(id response))successCompletion failer:(nullable void (^)(NSError *error))completion;
/**
 文件上传完毕后，通知后台
 @param groupid        groupId
 @param fileId         文件ID
 */
+ (void)uploadNotifyRequestWithGroupId:(NSString *)groupid permoption:(NSString *)permoption fileName:(NSString *)fileName fileType:(NSString *)fileType fileId:(NSString *)fileId completion:(nullable void (^)(NSError *error))completion;

/**
 *文件删除
*/
+ (void)deleteFileRequestWithGroupId:(NSString *)groupId fileId:(NSString *)fileId completion:(nullable void (^)(NSError *error))completion;

/**
 *文件申请下载
 * 回调字符串url 
 */
+ (void)applyForDownloadRequestWithGroupid:(NSString *)groupId fileId:(NSString *)fileId success:(nullable void(^)(id response))successCompletion completion:(nullable void (^)(NSError *error))completion;

#pragma mark - Group Announce

/**
 读群公告列表接口
 @param groupId        groupId
 @param announceId     上一次的最后一条公告的标志符，传 0代表是最新的
 @param successCompletion       成功回调，id<NSString>. means: reads
 */
+ (void)readAnnounceMentRequestWithGroupId:(NSString *)groupId announceId:(NSString *)announceId success:(nullable void(^)(id response))successCompletion completion:(nullable void (^)(NSError *error))completion;

/**
 获取群公告列表接口， 新接口
 @param groupId        groupId
 @param total          拉下来的数量，不超过30条
 @param announceId     上一次的最后一条公告的标志符，传 0代表是最新的
 @param successCompletion       成功回调，NSMutableArray<NSDictionary>
 */
+ (void)queryGroupAnnounceListWithGroupId:(NSString *)groupId total:(NSInteger)total announceId:(NSString *)announceId success:(nullable void(^)(id response))successCompletion completion:(nullable void (^)(NSError *error))completion;

/**
 创建群公告， 新接口
 @param groupId        groupId
 @param title          title
 @param content        content
 @param successCompletion       成功回调，NSDictionary <@{@"annountId":annountId,@"crateTime":crateTime};>
 */
+ (void)createGroupAnnnounceWithGroupId:(NSString *)groupId announceTitle:(NSString *)title announceContent:(NSString *)content success:(nullable void(^)(id response))successCompletion completion:(nullable void (^)(NSError *error))completion;

/**
 查询群公告， 单一公告
 @param groupId               groupId
 @param announceId            公告ID
 @param successCompletion      成功回调，
 */
+ (void)queryGroupSingleAnnounceWithGrupId:(NSString *)groupId announceTd:(NSString *)announceId success:(nullable void(^)(id response))successCompletion completion:(nullable void (^)(NSError *error))completion;

@end
